% author: Nicolas Schneider
% converts image to binaryimage
% input:  img  ... image to dilate
%         tresh  ... treshhold to decide when value is converted to 0 or 1
% output: BW ... binaryimage

function BW = mi2bw (img,tresh)

   if ndims(img)==3 % find out if img is rgb image
      img=grb2gray(img);
   end

   minmax = getrangefromclass(img);
   max=minmax(2);
   newtresh=max*tresh;
   BW = (img > newtresh);